package jiparada;

public class Node implements Comparable<Node> {

	//I will most definitely not explain this, I know it's ugly, but you can make it better :P
	public int x,y;
	private Node parent;
	public double  g_score, //real distance
	h_score; //heuristics distance

	public Node(int x, int y)
	{
		this.x=x;
		this.y=y;
	}
	
	public Node(){
	}

	public void setParent(Node parent)
	{
		this.parent = parent;
	}

	public Node getParent()
	{
		return parent;
	}

	public int compareTo(Node auxiliar)
	{
		return (int )(1000000*((this.g_score+this.h_score)-(auxiliar.g_score+auxiliar.h_score)));
	}

	public boolean equals(Object auxiliar)
	{
		if(this.x==((Node)auxiliar).x&&this.y==((Node)auxiliar).y)
			return true;


		return false;
	}

	public double getFScore()
	{
		return g_score+h_score;
	}

	public double calculateDistance(Node auxiliar)
	{
		int distanceX = Math.abs(this.x-auxiliar.x);
		int distanceY = Math.abs(this.y-auxiliar.y);

		if(distanceX<distanceY)
			return distanceX*Math.sqrt(2)+ distanceY-distanceX;
		else
			return distanceY*Math.sqrt(2)+ distanceX-distanceY;

	}


}
